<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/xizhongren8980/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/xizhongren8980/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/xizhongren8980/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/xizhongren8980/images/logo.svg" color="#222">

<link rel="stylesheet" href="/xizhongren8980/css/main.css">


<link rel="stylesheet" href="/xizhongren8980/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/xizhongren8980/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Maven定义Maven 是一个项目管理工具，它包含了一个项目对象模型（POM: Project Object Model），一组标准集合，一个项目生命周期，一个依赖管理系统以及用来运行定义在生命周期阶段中插件目标的逻辑。">
<meta property="og:type" content="article">
<meta property="og:title" content="Maven新手入门">
<meta property="og:url" content="https://gitee.com/xizhongren8980/xizhongren8980.git/2020/06/04/Maven%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8/index.html">
<meta property="og:site_name" content="一杯茶一包烟，一个BUG改一天">
<meta property="og:description" content="Maven定义Maven 是一个项目管理工具，它包含了一个项目对象模型（POM: Project Object Model），一组标准集合，一个项目生命周期，一个依赖管理系统以及用来运行定义在生命周期阶段中插件目标的逻辑。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604124508.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604125400.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604130913.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604131304.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604130326.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141550.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141600.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141606.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141612.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141619.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141627.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141633.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141646.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141651.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141919.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141821.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604142706.png">
<meta property="og:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604143052.png">
<meta property="article:published_time" content="2020-06-04T06:54:57.685Z">
<meta property="article:modified_time" content="2020-06-04T07:00:43.343Z">
<meta property="article:author" content="MisterTian">
<meta property="article:tag" content="Maven">
<meta property="article:tag" content="管理工具">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604124508.png">

<link rel="canonical" href="https://gitee.com/xizhongren8980/xizhongren8980.git/2020/06/04/Maven%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Maven新手入门 | 一杯茶一包烟，一个BUG改一天</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/xizhongren8980/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">一杯茶一包烟，一个BUG改一天</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">收藏永不停止，学习永不开始</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/xizhongren8980/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/xizhongren8980/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/xizhongren8980/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/xizhongren8980/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/xizhongren8980/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/xizhongren8980/xizhongren8980.git/2020/06/04/Maven%E6%96%B0%E6%89%8B%E5%85%A5%E9%97%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/xizhongren8980/images/head.jpg">
      <meta itemprop="name" content="MisterTian">
      <meta itemprop="description" content="一个小菜鸟">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一杯茶一包烟，一个BUG改一天">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Maven新手入门
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-04 14:54:57 / 修改时间：15:00:43" itemprop="dateCreated datePublished" datetime="2020-06-04T14:54:57+08:00">2020-06-04</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/xizhongren8980/categories/Maven/" itemprop="url" rel="index"><span itemprop="name">Maven</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="Maven定义"><a href="#Maven定义" class="headerlink" title="Maven定义"></a>Maven定义</h3><p><code>Maven</code> 是一个项目管理工具，它包含了一个<strong>项目对象模型（POM: Project Object Model）</strong>，一组标准集合，一个项目生命周期，一个依赖管理系统以及用来运行定义在生命周期阶段中插件目标的逻辑。<a id="more"></a></p>
<h3 id="Maven解决的问题"><a href="#Maven解决的问题" class="headerlink" title="Maven解决的问题"></a>Maven解决的问题</h3><p>在实际的项目开发过程中，我们需要引入各种 <code>jar</code> 包，其数量常常达到几十乃至上百个，如果我们全部通过手动把 <code>jar</code> 引入工程目录，不仅费事费力，往往还因为 <code>jar</code> 包的冲突让人直接怀疑人生。另一方面，对于具有相似架构的项目来说，每一个项目都需要引入 <code>jar</code> 包，也就是说相同的 <code>jar</code> 包就需要复制多份放置到不同工程中，这样无疑是白白浪费很多的存储空间。</p>
<p><code>maven</code> 的出现就很好的解决了上述问题，它可以帮我们从繁杂的工作中解放出来，可以为我们构件工程，管理 <code>jar</code> 包，编译代码，还能自动运行单元测试，打包，生成报表，甚至是帮我们部署项目，生成 <code>web</code> 站点。</p>
<h3 id="Maven核心作用"><a href="#Maven核心作用" class="headerlink" title="Maven核心作用"></a>Maven核心作用</h3><ul>
<li><p><strong>依赖管理</strong></p>
<p>与传统 Web 项目不同，Maven 项目不需要将所依赖的 jar 包直接复制到工程中，而是通过在 <code>pom.xml</code> 文件中添加所需 jar 包的坐标，在项目需要用到 jar 包的时候，只要通过 pom.xml 文件查找到相对应 jar 包的坐标，然后到 maven 仓库中找到 jar 包去运行。</p>
</li>
<li><p><strong>项目一键构建</strong></p>
<ul>
<li><p>构建是什么？</p>
<p>指的是项目从编译、测试、运行、打包、安装到部署这一过程都交给 maven 管理。</p>
</li>
</ul>
<p>一键构建也就是在整个构建过程，我们使用 maven 的一个命令即可完成整个工作。</p>
</li>
</ul>
<h3 id="maven-的使用"><a href="#maven-的使用" class="headerlink" title="maven 的使用"></a>maven 的使用</h3><ul>
<li><p><a href="http://maven.apache.org/download.cgi" target="_blank" rel="noopener">下载链接</a></p>
<p>找到适合自己操作系统的压缩包即可，以 Windows 系统为例，选择 .zip 压缩包。</p>
</li>
</ul>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604124508.png" alt="image-20200604123237481"></p>
<ul>
<li><p>安装</p>
<p>下载好后直接解压，然后放到想要安装的目录即可。例如我的是放在 <code>D:\Program Files\Java\Maven</code> 路径。</p>
</li>
<li><p>配置环境变量</p>
<p>安装好 maven 后还需要配置一下环境变量，类似于配置 jdk 路径，这里不再赘述。</p>
</li>
<li><p>测试配置是否成功</p>
<p>在命令行行窗口输入 <code>mvn -v</code> ，如果出现版本信息则配置成功，类似于下图。</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604125400.png" alt="image-20200604125358440"></p>
</li>
</ul>
<h3 id="在-IDEA-中使用-maven"><a href="#在-IDEA-中使用-maven" class="headerlink" title="在 IDEA 中使用 maven"></a>在 IDEA 中使用 maven</h3><ul>
<li><p>更改 maven 本地仓库路径</p>
<p>打开路径 <code>\Maven\apache-maven-3.6.3\conf</code> 下的 settings.xml 文件，按图中所示进行更改，路径自行选择。</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604130913.png" alt="image-20200604130911635"></p>
</li>
<li><p>设置 maven 镜像</p>
<p>配置镜像可以有效加快依赖下载速度。</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604131304.png" alt="image-20200604131302766"></p>
</li>
</ul>
  <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--配置阿里云Maven镜像--&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">mirror</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span>&gt;</span>nexus-aliyun<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">mirrorOf</span>&gt;</span>central<span class="tag">&lt;/<span class="name">mirrorOf</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">name</span>&gt;</span>Nexus aliyun<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://maven.aliyun.com/nexus/content/groups/public<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">mirror</span>&gt;</span></span><br><span class="line">     <span class="comment">&lt;!--配置华为云Maven镜像--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mirror</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span>&gt;</span>huaweicloud<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">mirrorOf</span>&gt;</span>*<span class="tag">&lt;/<span class="name">mirrorOf</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">url</span>&gt;</span>https://mirrors.huaweicloud.com/repository/maven/<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">mirror</span>&gt;</span></span><br></pre></td></tr></table></figure>



<ul>
<li><p>配置 maven </p>
<p>在 IDEA 首页，点击 <code>Configure - settings</code> ，找到如图所示，根据自己的实际安装情况进行填写即可。</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604130326.png" alt="image-20200604130323470"></p>
</li>
</ul>
<ul>
<li><p>创建 maven 工程</p>
<ul>
<li>选择 Maven 模板</li>
</ul>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141550.png" alt="image-20200604132036492"></p>
<ul>
<li>填写基本信息</li>
</ul>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141600.png" alt="image-20200604132222329"></p>
<ul>
<li><p>确认一下项目路径以及项目名称，最后点击 Finish </p>
<img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141606.png" alt="image-20200604132816494" style="zoom:80%;" />
</li>
</ul>
</li>
<li><p>项目基本结构</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141612.png" alt="image-20200604133203228"></p>
</li>
<li><p>编写一个简单类</p>
<p>首先在 java 路径下建立自己的包，例如 com.hello_maven，然后在该包下编写一个简单类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.hello_maven;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloMaven</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">hello</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"hello maven"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><p>编写测试代码</p>
<p>测试代码路径与类路径要一一对应</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141619.png" alt="image-20200604135628268"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.hello_maven;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.junit.Test;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloMavenTest</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">hello</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        HelloMaven helloMaven = <span class="keyword">new</span> HelloMaven();</span><br><span class="line">        System.out.println(helloMaven.hello());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>引入 junit 测试包</p>
<p>找到 pom.xml 文件，导入 junit 依赖</p>
<img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141627.png" alt="image-20200604135817221" style="zoom:50%;" />



</li>
</ul>
<ul>
<li><p>运行测试代码观察输出</p>
<img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141633.png" alt="image-20200604140003266" style="zoom: 50%;" />

<p>以上就是在 IDEA 中初次使用 maven 模板创建工程的的步骤。</p>
</li>
</ul>
<h3 id="Maven-常用命令"><a href="#Maven-常用命令" class="headerlink" title="Maven 常用命令"></a>Maven 常用命令</h3><ul>
<li><p>compile</p>
<p>compile 是 maven 工程的编译命令，作用是将 src/main/java 下的文件编译为 class 文件输出到 target 目录下。 </p>
<p>命令执行前目录</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141646.png" alt="image-20200604141325571"></p>
<p><code>mvn compile</code> 命令执行后目录，可以看到多出了一个 target 目录。</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141651.png" alt="image-20200604141435130"></p>
</li>
<li><p>test</p>
<p>test 是 maven 工程的测试命令  mvn test，会执行src/test/java下的单元测试类。 cmd 执行 mvn test 执行 src/test/java 下单元测试类，下图为测试结果，运行 1 个测试用例，全部成功。</p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141919.png" alt="image-20200604141916818"></p>
<img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604141821.png" alt="image-20200604141810692" style="zoom: 80%;" />

<p>可以看到，在 target 文件夹的基础上，多出了两个测试文件夹。</p>
</li>
<li><p>clean</p>
<p>clean 是 maven 工程的清理命令，执行 clean 会删除 target 目录及内容。 </p>
</li>
<li><p>package</p>
<p>package 是 maven 工程的打包命令，对于 java 工程执行 package 打成 jar 包，对于web 工程打成war 包。 </p>
<img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604142706.png" alt="image-20200604142700061" style="zoom:50%;" />
</li>
<li><p>install</p>
<p>install 是 maven 工程的安装命令，执行 install 将 maven 打成 jar 包或 war 包发布到本地仓库。 </p>
<p><img src="https://gitee.com//xizhongren8980/BlogImages/raw/master/imgs/20200604143052.png" alt="image-20200604143049122"></p>
</li>
</ul>
<h4 id="常用命令作用范围之间的关系"><a href="#常用命令作用范围之间的关系" class="headerlink" title="常用命令作用范围之间的关系"></a>常用命令作用范围之间的关系</h4><figure class="highlight ada"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">compile &lt;  test &lt;  <span class="keyword">package</span> <span class="title">&lt;  install</span></span><br></pre></td></tr></table></figure>

<p>范围大的命令会执行时，还会把范围小的命令执行一次。也就是说，即使现在不执行 compile 和 test 命令就执行 package 命令，同样会在 target 目录有由 compile 和 test 命令产生的文件。</p>
<h3 id="pom-xml-文件参数配置解读"><a href="#pom-xml-文件参数配置解读" class="headerlink" title="pom.xml 文件参数配置解读"></a>pom.xml 文件参数配置解读</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span></span></span><br><span class="line"><span class="tag">         <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag">         <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">modelVersion</span>&gt;</span>4.0.0<span class="tag">&lt;/<span class="name">modelVersion</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.hello_maven<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>hello_maven<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0-SNAPSHOT<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>junit<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>junit<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>4.13<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>test<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">project</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight ada"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&lt;project&gt; : 文件的根节点</span><br><span class="line">&lt;modelversion&gt; : <span class="type">pom.xml</span> 使用的对象模型版本</span><br><span class="line">&lt;groupId&gt; : 项目名称，一般写项目的域名</span><br><span class="line">&lt;artifactId&gt; : 模块名称，子项目名或模块名称</span><br><span class="line">&lt;version&gt; : 产品的版本号，<span class="type">SNAPSHOT</span>为非正式版本，RELEASE为正式发布版本</span><br><span class="line">&lt;packaging&gt; : 打包类型，一般有 <span class="type">jar</span>、war、pom 等 </span><br><span class="line">&lt;name&gt; : 项目的显示名，常用于 <span class="type">Maven</span> 生成的文档</span><br><span class="line">&lt;description&gt; : 项目描述，常用于 <span class="type">Maven</span> 生成的文档</span><br><span class="line">&lt;dependencies&gt; : 项目依赖构建配置，配置项目依赖构件的坐标</span><br><span class="line">&lt;build&gt; : 项目构建配置，配置编译，运行插件等</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/xizhongren8980/tags/Maven/" rel="tag"># Maven</a>
              <a href="/xizhongren8980/tags/%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7/" rel="tag"># 管理工具</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/xizhongren8980/2020/05/27/%E3%80%90%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3Java%E3%80%91%E4%B9%8B%20ThreadLocal/" rel="prev" title="【深入理解Java】之 ThreadLocal">
      <i class="fa fa-chevron-left"></i> 【深入理解Java】之 ThreadLocal
    </a></div>
      <div class="post-nav-item">
    <a href="/xizhongren8980/2020/06/04/%E3%80%90MyBatis%E5%85%A5%E9%97%A8%E3%80%91%E4%B9%8B%E5%88%9D%E8%AF%86MyBatis/" rel="next" title="【MyBatis入门_01】之初识MyBatis">
      【MyBatis入门_01】之初识MyBatis <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven定义"><span class="nav-number">1.</span> <span class="nav-text">Maven定义</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven解决的问题"><span class="nav-number">2.</span> <span class="nav-text">Maven解决的问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven核心作用"><span class="nav-number">3.</span> <span class="nav-text">Maven核心作用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#maven-的使用"><span class="nav-number">4.</span> <span class="nav-text">maven 的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在-IDEA-中使用-maven"><span class="nav-number">5.</span> <span class="nav-text">在 IDEA 中使用 maven</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven-常用命令"><span class="nav-number">6.</span> <span class="nav-text">Maven 常用命令</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#常用命令作用范围之间的关系"><span class="nav-number">6.1.</span> <span class="nav-text">常用命令作用范围之间的关系</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pom-xml-文件参数配置解读"><span class="nav-number">7.</span> <span class="nav-text">pom.xml 文件参数配置解读</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="MisterTian"
      src="/xizhongren8980/images/head.jpg">
  <p class="site-author-name" itemprop="name">MisterTian</p>
  <div class="site-description" itemprop="description">一个小菜鸟</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/xizhongren8980/archives/">
        
          <span class="site-state-item-count">57</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/xizhongren8980/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/xizhongren8980/tags/">
          
        <span class="site-state-item-count">101</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://mistertian8980.github.io/" title="https:&#x2F;&#x2F;mistertian8980.github.io&#x2F;" rel="noopener" target="_blank">Github博客</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">MisterTian</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="/xizhongren8980/lib/canvas-ribbon/canvas-ribbon.js"></script>
  <script src="/xizhongren8980/lib/anime.min.js"></script>
  <script src="/xizhongren8980/lib/velocity/velocity.min.js"></script>
  <script src="/xizhongren8980/lib/velocity/velocity.ui.min.js"></script>

<script src="/xizhongren8980/js/utils.js"></script>

<script src="/xizhongren8980/js/motion.js"></script>


<script src="/xizhongren8980/js/schemes/pisces.js"></script>


<script src="/xizhongren8980/js/next-boot.js"></script>


  <script defer src="//cdn.jsdelivr.net/gh/theme-next/theme-next-three@1/three.min.js"></script>
    <script defer src="//cdn.jsdelivr.net/gh/theme-next/theme-next-three@1/canvas_lines.min.js"></script>


  




  
<script src="/xizhongren8980/js/local-search.js"></script>













  

  

</body>
</html>
